// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//

// Implement a simple JSON representation format for arrays

#pragma once

#include <memory>
#include <string>
#include <string_view>

#include <turbo/utility/status.h>
#include <nebula/types/type_fwd.h>
#include <turbo/base/macros.h>

namespace nebula::ipc::json {


    TURBO_EXPORT
    turbo::Result<std::shared_ptr<Array>> array_from_json(const std::shared_ptr<DataType> &,
                                                        std::string_view json);


    TURBO_EXPORT
    turbo::Status chunked_array_from_json(const std::shared_ptr<DataType> &type,
                                       const std::vector<std::string> &json_strings,
                                       std::shared_ptr<ChunkedArray> *out);

    TURBO_EXPORT
    turbo::Status dict_array_from_json(const std::shared_ptr<DataType> &, std::string_view indices_json,
                                    std::string_view dictionary_json, std::shared_ptr<Array> *out);

    TURBO_EXPORT
   turbo::Result<std::shared_ptr<Array>> dict_array_from_json(const std::shared_ptr<DataType> &type, std::string_view indices_json,
                                   std::string_view dictionary_json);

    TURBO_EXPORT
    turbo::Status scalar_from_json(const std::shared_ptr<DataType> &, std::string_view json,
                                 std::shared_ptr<Scalar> *out);

    TURBO_EXPORT
    turbo::Status dict_scalar_from_json(const std::shared_ptr<DataType> &, std::string_view index_json,
                                     std::string_view dictionary_json, std::shared_ptr<Scalar> *out);

}  // namespace nebula::ipc::json
